package com.scau.phradmin.business.healthRecord.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.scau.phradmin.common.util.PageDTO;
import com.scau.phradmin.domain.entity.HealthRecord;
import com.scau.phradmin.domain.mapper.HealthRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class HealthRecordService {
    @Autowired
    private HealthRecordMapper healthRecordMapper;
    /**
     * 查询所有用户信息
     * @param pages
     * @return
     */
    public PageDTO<HealthRecord> selectAll(int pages){
        Page page=null;
        if(pages>0) {
            page=new Page(pages,10);
        }
        else{
            page=new Page(1,10);
        }
        List<HealthRecord> list=healthRecordMapper.queryAll(page);
        return PageDTO.valueOf(list,page);
    }

    /**
     * 通过id查询唯一用户信息
     * @param id
     * @return
     */
    public Object selectById(Long id){
        return healthRecordMapper.queryOne(id);
    }

    /**
     * 通过主键修改唯一用户信息，成功返回true，否则返回false
     * @param healthRecord
     * @return
     */

    @Transactional
    public boolean edit(HealthRecord healthRecord){
        return healthRecordMapper.updateById(healthRecord)>0;
    }

    /**
     * 添加用户
     * @param healthRecord
     * @return
     */
    @Transactional
    public boolean add(HealthRecord healthRecord){
        return healthRecordMapper.insert(healthRecord) > 0;
    }

    /**
     * 通过id删除唯一用户
     * @param id
     * @return
     */
    @Transactional
    public boolean delete(Long id){
        return healthRecordMapper.deleteById(id) > 0;
    }
}
